package com.example.designpattern.singleExample;

import java.io.Serializable;

/**
 * @program: DesignPattern
 * @description: 双重检测锁创建单例bean
 * @author: zhangjt
 * @create: 2024-11-14 14:46
 **/
public class NoReflectDulLazyCreateBean implements Serializable {
    private static volatile NoReflectDulLazyCreateBean instance;

    private NoReflectDulLazyCreateBean(){
        if (instance != null){
            throw new RuntimeException("单例不允许多个实例");
        }
    }

    public static NoReflectDulLazyCreateBean getInstance(){
        if(instance == null){
            synchronized (NoReflectDulLazyCreateBean.class){
                if(instance == null){
                    instance = new NoReflectDulLazyCreateBean();
                }
            }
        }
        return instance;
    }
}
